﻿#include "LocalConf.h"
#include "../util/TextUtil.h"
#include "../util/SystemHelper.h"

LocalConf::LocalConf(void)
{
	m_id = TextUtil::get_mutable_instance().GetGuid();
	m_url = "http://127.0.0.1:5002";
	m_user = "dondown_client_id";
	m_password = "dondown_client_secret";
	m_auth = ("/auth/oauth2");
	m_http_ip = SystemHelper::get_mutable_instance().GetLocalIp();
	m_http_port = 5700;
	m_use_ssl = false;
	m_preview = true;
}

LocalConf::~LocalConf(void)
{
}

std::string LocalConf::GetId()
{
	return m_id;
}

void LocalConf::SetId(std::string id)
{
	m_id = id;
}

std::string LocalConf::GetUrl()
{
	return m_url;
}

void LocalConf::SetUrl(std::string url)
{
	m_url = url;
}

std::string LocalConf::GetUser()
{
	return m_user;
}

void LocalConf::SetUser(std::string user)
{
	m_user = user;
}

std::string LocalConf::GetPassword()
{
	return m_password;
}

void LocalConf::SetPassword(std::string pwd)
{
	m_password = pwd;
}

std::string LocalConf::GetAuthUrl()
{
	return m_auth;
}

void LocalConf::SetAuthUrl(std::string auth)
{
	m_auth = auth;
}

std::string LocalConf::GetHttpIp()
{
	return m_http_ip;
}

void LocalConf::SetHttpIp(std::string ip)
{
	m_http_ip = ip;
}

int LocalConf::GetHttpPort()
{
	return m_http_port;
}

void LocalConf::SetHttpPort(int port)
{
	m_http_port = port;
}

bool LocalConf::GetUseSSL()
{
	return m_use_ssl;
}

void LocalConf::SetUseSSL(bool ssl)
{
	m_use_ssl = ssl;
}

bool LocalConf::GetPreview()
{
	return m_preview;
}

void LocalConf::SetPreview(bool preview)
{
	m_preview = preview;
}

std::string LocalConf::GetImageUrl(std::string id)
{
	// python : str("http://" + Global.fileIp + ":" + str(Global.filePort) + "/device/lastImage?id=" + _id)
	std::string url;
	if (m_use_ssl)
	{
		url = "https://";
	}
	else
	{
		url = "http://";
	}
	url += m_http_ip;
	url += ":";
	url += std::to_string(m_http_port);
	url += "/device/lastImage?id=";
	url += id;
	return url;
}

std::string LocalConf::GetAlarmUrl(std::string id)
{
	// python : str("http://" + Global.fileIp + ":" + str(Global.filePort) + "/alarm/image?id=" + _id)
	std::string url;
	if (m_use_ssl)
	{
		url = "https://";
	}
	else
	{
		url = "http://";
	}
	url += m_http_ip;
	url += ":";
	url += std::to_string(m_http_port);
	url += "/alarm/image?id=";
	url += id;
	return url;
}

std::string LocalConf::GetRecordUrl(std::string id)
{
	// python : str("http://" + Global.fileIp + ":" + str(Global.filePort) + "/alarm/record?id=" + _id)
	std::string url;
	if (m_use_ssl)
	{
		url = "https://";
	}
	else
	{
		url = "http://";
	}
	url += m_http_ip;
	url += ":";
	url += std::to_string(m_http_port);
	url += "/alarm/record?id=";
	url += id;
	return url;
}

std::string LocalConf::GetManualUrl(std::string id)
{
	// python : str("http://" + Global.fileIp + ":" + str(Global.filePort) + "/record/download?id=" + _id)
	std::string url;
	if (m_use_ssl)
	{
		url = "https://";
	}
	else
	{
		url = "http://";
	}
	url += m_http_ip;
	url += ":";
	url += std::to_string(m_http_port);
	url += "/record/download?id=";
	url += id;
	return url;
}

std::string LocalConf::GetFileUrl(std::string name)
{
	// python : str("http://" + Global.fileIp + ":" + str(Global.filePort) + "/file/download?name=" + model_id + '.pt')
	std::string url;
	if (m_use_ssl)
	{
		url = "https://";
	}
	else
	{
		url = "http://";
	}
	url += m_http_ip;
	url += ":";
	url += std::to_string(m_http_port);
	url += "/file/download?name=";
	url += name;
	return url;
}